import WConio
import string

def clrline():
    y = WConio.wherey()
#    WConio.insline()
    WConio.gotoxy(0, y)
    WConio.clreol()

def getword(wd):
    line = ''
    color = []
    k = 0
    while wd != line:
        ch = WConio.getch()[1]
        if not ch in string.ascii_lowercase:
            if ord(ch) == 8:
                line = line[0:len(line)-1]
                color = color[0:len(color)-1]
                k -= 1
                clrline()
                WConio.textattr(WConio.WHITE)
                for j in range(len(line)):
                    WConio.textattr(color[j])
                    WConio.cputs(line[j])
                continue

            if ord(ch) != 13: continue
            clrline()

            WConio.textattr(WConio.WHITE)
            line = ''
            k = 0
            color = []
        else:
            if (len(wd) <= k) or wd[k] != ch:
                color.append(WConio.LIGHTRED)
                WConio.textattr(WConio.LIGHTRED)
            else:
                if len(color) == 0:
                    color.append(WConio.WHITE)
                else:
                    color.append(color[len(color)-1])
            WConio.cputs(ch)
            k += 1
            line += ch

    WConio.textattr(WConio.LIGHTGREEN)
    clrline()
    WConio.cputs(line + '\n')
    WConio.textattr(WConio.WHITE)


getword('hello')
getword('world')
